#include "GraphicsLibrary.h"

Rgb::Rgb(void)
{
	red = 1.0;
	green = 1.0;
	blue = 1.0;
	alpha = 1.0;
}

Rgb::Rgb(double red, double green, double blue, double alpha)
{
	this->red = red;
	this->green = green;
	this->blue = blue;
	this->alpha = alpha;
}

Rgb operator + (const Rgb &clr0, const Rgb &clr1)
{
	return Rgb(clr0.red + clr1.red, clr0.green + clr1.green, clr0.blue + clr1.blue);
}

Rgb operator - (const Rgb &clr0, const Rgb &clr1)
{
	return Rgb(clr0.red - clr1.red, clr0.green - clr1.green, clr0.blue - clr1.blue);
}

Rgb operator * (const Rgb &clr0, const Rgb &clr1)
{
	return Rgb(clr0.red * clr1.red, clr0.green * clr1.green, clr0.blue * clr1.blue);
}

Rgb operator * (const Rgb &clr, double scalar)
{
	return Rgb(scalar * clr.red, scalar * clr.green, scalar * clr.blue);
}

Rgb operator * (double scalar, const Rgb &clr)
{
	return Rgb(scalar * clr.red, scalar * clr.green, scalar * clr.blue);
}

Rgb operator / (const Rgb &clr, double scalar)
{
	if (ABS(scalar) < 1e-4)
	{
		scalar = 1.0;
	}

	return Rgb(clr.red / scalar, clr.green / scalar, clr.blue / scalar);
}

Rgb operator += (Rgb &clr0, Rgb &clr1)
{
	clr0.red += clr1.red;
	clr0.green += clr1.green;
	clr0.blue += clr1.blue;
	return clr0;
}

Rgb operator += (Rgb & clr0, Rgb && clr1)
{
	clr0.red += clr1.red;
	clr0.green += clr1.green;
	clr0.blue += clr1.blue;
	return clr0;
}

Rgb operator -= (Rgb &clr0, Rgb &clr1)
{
	clr0.red -= clr1.red;
	clr0.green -= clr1.green;
	clr0.blue -= clr1.blue;
	return clr0;
}

Rgb operator -= (Rgb & clr0, Rgb && clr1)
{
	clr0.red -= clr1.red;
	clr0.green -= clr1.green;
	clr0.blue -= clr1.blue;
	return clr0;
}

Rgb operator *= (Rgb &clr0, Rgb &clr1)
{
	clr0.red *= clr1.red;
	clr0.green *= clr1.green;
	clr0.blue *= clr1.blue;
	return clr0;
}

Rgb operator *= (Rgb & clr0, Rgb && clr1)
{
	clr0.red *= clr1.red;
	clr0.green *= clr1.green;
	clr0.blue *= clr1.blue;
	return clr0;
}

Rgb operator /= (Rgb &clr, double scalar)
{
	if (ABS(scalar) < 1e-4)
	{
		scalar = 1.0;
	}
	clr.red /= scalar;
	clr.green /= scalar;
	clr.blue /= scalar;
	return clr;
}

void Rgb::Normalize(void)
{
	red = (red < 0.0) ? 0.0 : ((red > 1.0) ? 1.0 : red);
	green = (green < 0.0) ? 0.0 : ((green > 1.0) ? 1.0 : green);
	blue = (blue < 0.0) ? 0.0 : ((blue > 1.0) ? 1.0 : blue);
}